<template>
  <div id="app">
    <div class="head">
      <div class="head_content">
        <van-icon name="arrow-left" size=".3rem" color="#fff" />
        <div class="head_title">搜索</div>
      </div>
    </div>
    <div class="search_content">
      <div class="form_item">
        <div class="select_pop">
          <label>产品名称</label>
          <div>
            <input
              type="text"
              v-model.trim="ProductName"
              placeholder="请输入"
              @input="productInput"
            />
            <van-icon name="arrow-down" size=".24rem" color="#828FB2" />
          </div>
          <ul class="reslist" v-if="productRESList.length > 0">
            <li
              v-for="item in productRESList"
              :key="item"
              @click="
                ProductName = item;
                productRESList = [];
              "
            >
              {{ item }}
            </li>
          </ul>
        </div>
      </div>
      <div class="form_item">
        <div class="select_pop">
          <label>客户名称</label>
          <div @click="showCustomer = true">
            <input
              type="text"
              v-model="CustomerName"
              placeholder="请选择"
              @input="customerInput"
            />
            <van-icon name="arrow-down" size=".24rem" color="#828FB2" />
          </div>
          <ul class="reslist" v-if="customerRESList.length > 0">
            <li
              v-for="item in customerRESList"
              :key="item"
              @click="
                CustomerName = item;
                customerRESList = [];
              "
            >
              {{ item }}
            </li>
          </ul>
        </div>
      </div>
      <div class="form_item">
        <div class="select_pop">
          <label>状态</label>
          <div @click="showOrderStatus = true">
            <input type="text" v-model="OrderStatus" placeholder="请选择" />
            <van-icon name="arrow-down" size=".24rem" color="#828FB2" />
          </div>
        </div>
      </div>
      <div class="form_item">
        <div class="select_pop">
          <label>版本号</label>
          <div @click="showVersion = true">
            <input
              type="text"
              v-model="Version"
              placeholder="请选择"
              @input="VersionInput"
            />
            <van-icon name="arrow-down" size=".24rem" color="#828FB2" />
          </div>
          <ul class="reslist" v-if="VersionRESList.length > 0">
            <li
              v-for="item in VersionRESList"
              :key="item"
              @click="
                Version = item;
                VersionRESList = [];
              "
            >
              {{ item }}
            </li>
          </ul>
        </div>
      </div>
      <div class="form_item" style="text-align: center;padding-top: .4rem;">
        <button class="btn danger" @click="resetFrom">重置</button>
        <button class="btn primary" @click="searchRes">确定</button>
      </div>
      <div class="search_bg_img">
        <img src="../../assets/search_bt.png" />
      </div>
    </div>
    <van-popup v-model="showOrderStatus" round position="bottom">
      <van-picker
        show-toolbar
        :columns="stateList"
        @cancel="showOrderStatus = false"
        @confirm="onConfirmOrderStatus"
      />
    </van-popup>
  </div>
</template>
<script>
import { Toast } from "vant";
import { listVersion, listCustomer, listProduct } from "../../api/";
export default {
  name: "search",
  data() {
    return {
      ProductName: "",
      CustomerName: "",
      OrderStatus: "",
      Version: "",
      showCustomer: false,
      showOrderStatus: false,
      showVersion: false,
      VersionList: [],
      VersionRESList: [],
      productList: [],
      productRESList: [],
      customerList: [],
      customerRESList: [],
      stateList: ["已签收", "备货中", "已发运", "未备货"]
    };
  },
  // watch:{
  //     CustomerName:{

  //     }
  // },
  methods: {
    customerInput() {
      let query = this.CustomerName;
      if (query != "") {
        this.customerRESList = this.customerList.filter(item => {
          return item.toLowerCase().indexOf(query.toLowerCase()) > -1;
        });
      } else {
        this.customerRESList = this.customerList;
      }
    },
    productInput() {
      let query = this.ProductName;
      if (query != "") {
        this.productRESList = this.productList.filter(item => {
          return item.toLowerCase().indexOf(query.toLowerCase()) > -1;
        });
      } else {
        this.productRESList = this.productList;
      }
      console.log(this.productRESList, "this.productRESList");
    },
    VersionInput() {
      let query = this.Version;
      if (query != "") {
        this.VersionRESList = this.VersionList.filter(item => {
          return item.toLowerCase().indexOf(query.toLowerCase()) > -1;
        });
      } else {
        this.VersionRESList = this.VersionList;
      }
    },
    onConfirmOrderStatus(selectedOptions) {
      this.OrderStatus = selectedOptions;
      this.showOrderStatus = false;
    },
    resetFrom() {
      this.ProductName = "";
      this.CustomerName = "";
      this.OrderStatus = "";
      this.Version = "";
    },
    getListCustomer() {
      listCustomer({ Satrap: "郭巧娜" }).then(res => {
        this.customerList = res.data;
        this.customerRESList = res.data;
      });
    },
    getListVersion() {
      listVersion({ Satrap: "郭巧娜" }).then(res => {
        this.VersionList = res.data;
        this.VersionRESList = res.data;
      });
    },
    getListProduct() {
      listProduct({ Satrap: "郭巧娜" }).then(res => {
        this.productList = res.data;
        this.productRESList = res.data;
      });
    },
    searchRes() {
      if (this.Version == "") {
        Toast.fail("请选择版本号");
        return;
      }
      this.$router.push({
        name: "orderList",
        params: {
          ProductName: this.ProductName,
          CustomerName: this.CustomerName,
          OrderStatus: this.OrderStatus,
          Version: this.Version
        }
      });
    }
  },
  mounted() {
    console.log(this.$route.query.name, 987);
    this.getListCustomer();
    this.getListVersion();
    this.getListProduct();
  }
};
</script>
<style type="text/css" scoped>
.head {
  width: 100%;
  height: 1.76rem;
  background-repeat: no-repeat;
  background-size: cover;
  background-image: url(../../assets/search_head.jpg);
  display: flex;
  flex-direction: column-reverse;
}
.head_content {
  width: 100%;
  padding: 0.3rem 0.21rem;
  display: flex;
  justify-content: flex-start;
  flex-direction: row;
  align-items: center;
  box-sizing: border-box;
}
.head_content .head_title {
  font-size: 0.32rem;
  font-weight: 400;
  color: #ffffff;
  width: calc(100% - 0.6rem);
  text-align: center;
}
.search_content {
  width: 100%;
  min-height: calc(100vh - 1.76rem);
  background: linear-gradient(180deg, #ffffff 0%, #ffffff 48%, #ffebeb 100%);
  box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.16);
  padding: 0.7rem;
  box-sizing: border-box;
}
.form_item {
  padding: 0.35rem 0;
}
.select_pop {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  position: relative;
}
.select_pop label {
  width: 1.5rem;
  display: block;
  font-size: 0.28rem;
  font-family: PingFang SC-Bold, PingFang SC;
  font-weight: bold;
  color: #000000;
  line-height: 0px;
}
.select_pop > div {
  width: calc(100% - 1.5rem);
  height: 0.7rem;
  background: #f4f4f6;
  border-radius: 8px 8px 8px 8px;
  opacity: 0.8;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 0 0.2rem;
}
.reslist {
  z-index: 150;
  display: none;
  position: absolute;
  top: 0.7rem;
  left: 1.5rem;
  background: #fff;
  max-height: 3rem;
  overflow: auto;
  padding: 0.1rem;
  border-radius: 0.16rem;
  box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.16);
  width: calc(100% - 1.5rem);
}
.reslist li {
  width: 100%;
  display: block;
  font-size: 0.24rem;
  line-height: 0.5rem;
}
.select_pop:hover .reslist {
  display: block;
}
.select_pop div input {
  border: none;
  background: #f4f4f6;
  font-size: 0.24rem;
  width: calc(100% - 0.24rem);
  font-weight: 400;
  height: 100%;
}
.search_bg_img {
  /*position: absolute;
        width: 100vw;
        left: 0;
        right: 0;
        bottom: 1.4rem;*/
  margin-top: 0.8rem;
  width: 100%;
}
.search_bg_img img {
  width: 4.97rem;
  height: 3.27rem;
  margin: auto;
  display: block;
}
.btn {
  display: inline-block;
  width: 2.24rem;
  height: 0.8rem;
  line-height: 0;
  font-size: 0.32rem;
  text-align: center;
  background: #fff;
  border-radius: 0.41rem;
  border: 1px solid #c90000;
  margin: 0.15rem 0.35rem;
}
.btn.primary {
  background: #c90000;
  color: #fff;
}
.btn.danger {
  background: #fff;
  color: #c90000;
}
</style>
